import { mergeConfig } from 'vite';
import baseConfig from './vite.config.base';
import configCompressPlugin from './plugin/compress';
import configVisualizerPlugin from './plugin/visualizer';
import configArcoResolverPlugin from './plugin/arcoResolver';
import configStyleImportPlugin from './plugin/styleImport';
import configImageminPlugin from './plugin/imagemin';
import path from 'node:path'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite';
import zipPack from 'vite-plugin-zip-pack'
import deletePack from '../vite/plugins/delete-pack'
const outDir = 'sub2'; // 输出文件夹名称
const outFileName = `${outDir}.zip`;
export default mergeConfig(
  {
    mode: 'production',
    plugins: [
      configCompressPlugin('gzip'),
      configVisualizerPlugin(),
      configArcoResolverPlugin(),
      configStyleImportPlugin(),
      configImageminPlugin(),
      Components(),
      zipPack({
        inDir: outDir,
        outDir: '.',
        outFileName: outFileName,
        pathPrefix: '',
      }),
      deletePack({
        targets: [`${outDir}`], // 需要删除的文件或文件夹
      }),
    ],
    build: {
      outDir: outDir,
      rollupOptions: {
        output: {
          manualChunks: {
            arco: ['@arco-design/web-vue'],
            // chart: ['echarts', 'vue-echarts'],
            vue: ['vue', 'vue-router', 'pinia', '@vueuse/core', 'vue-i18n'],
          },
        },
        // 生产环境移除console
        minify: 'terser',
        terserOptions: {
          compress: {
            //生产环境时移除console
            drop_console: true,
            drop_debugger: true,
          },
        },
      },
      chunkSizeWarningLimit: 2000,
    },
    resolve: {
      alias: {
        '~/': `${path.resolve(__dirname, 'src')}/`,
        '@': path.resolve(__dirname, 'src'),
        // '~@': `${path.resolve(__dirname, 'src')}/`,
      },
    },
  },
  baseConfig
);
